package com.example.whatsnext;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;


public class HomeActivity extends Activity {	

	 // XML node keys    
    public static final String KEY_NAME = "name";
    public static final String KEY_LASTMESSAGE = "lastMessage";
    public static final String KEY_COUNT_MISSED_MESSAGES = "missedMessages";
    public static final String KEY_THUMB_URL = "thumb_url";
	
    private ListView chatsList;
    private ChatAdapter chatAdapter;
	
	 @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		
		// Create progress bar to display while the list loads
		//ProgressBar progressBar = new ProgressBar(this);
		//progressBar.setLayoutParams(new LayoutParams(Gravity.CENTER,
		//		Gravity.CENTER));
		//progressBar.setIndeterminate(true);
		//getListView().setEmptyView(progressBar);
		
		
	   ArrayList<HashMap<String, String>> chats = new ArrayList<HashMap<String,String>>();
	   
	   
	   // TODO Implement the data connection
	   for (int i = 0; i < 10; i++) 
	   {
		   HashMap<String, String> map = new HashMap<String, String>();
		   map.put(KEY_NAME, "Dennis");
		   map.put(KEY_LASTMESSAGE, "Das war ich nicht!");
		   map.put(KEY_COUNT_MISSED_MESSAGES, "4");
		   
		   chats.add(map);
	   }
		    
	   chatsList = (ListView)findViewById(R.id.listContactsView);
	   
	   // Getting adapter by passing data ArrayList
	   chatAdapter = new ChatAdapter(this, chats);
	   chatsList.setAdapter(chatAdapter);
	   
	   // Click Event for single row
	   chatsList.setOnItemClickListener(new OnItemClickListener() 
	   {
		  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
		  {
			  Intent intent = new Intent(view.getContext(), ChatActivity.class);
			  intent.putExtra("Test", "Test");
			  
			  startActivity(intent);
		  }		
	   });

	}	
	 
	 public void onPause() 
	 {
		super.onPause();  // Always call the superclass method first	
	 }
	 
	 protected void onStop() 
	 {
		    super.onStop();  // Always call the superclass method first		   
	 }
	 
	 public void onRestoreInstanceState(Bundle savedInstanceState) 
	 {
		    // Always call the superclass so it can restore the view hierarchy
		    super.onRestoreInstanceState(savedInstanceState);   
	 }
	
	// Called when a new Loader needs to be created
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		
		//getMenuInflater().inflate(R.menu.activity_home, menu);
		return true;
	}	

}
